예제를 따라해보았는데 온도 습도가 0으로 표시됩니다.
DHT 11 대신 DHT22를 사용하여
예제에있는 11을 모두 22로 바꿔 진행하였습니다.
#include <DHT.h>
#define DHTPIN A2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x5};
IPAddress ip(192, 168, 0, 32);
// IP 주소는 " XXX,XXX,XXX,XXX " ',' 주의해주세요.
// 이더넷 라이브러리 초기화
// 사용할 IP 주소 와 포트 입력
// ('port 80' 은 HTTP 의 기본 값 입니다.):
EthernetServer server(80);
void client();
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // 포트 연결까지 기다리기. 레오나르도에만 필요합니다.
}
// 이더넷 서버 연결 시작:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == 'n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// 브라우저 5초마다 새로고침
client.print("<meta http-equiv="refresh" content="5">");
client.println("<title>");
client.print("Welcome EDUINO");
client.println("</title>");
int h = dht.readHumidity();
int t = dht. readTemperature();
// 온습도센서(DHT-22)로부터 값 출력
client.println("<center>");
client.println("<h1>");
client.print("EDUINO Office");
client.println("</h1>");
client.println("<h2>");
client.print("Office Temperature and Humidity");
client.println("</h2>");
client.println("<h4>");
client.print("Temperature : ");
client.print(t);
client.print("<sup>0</sup>");
client.print("C");
client.println("<br />");
client.print("Humidity : ");
client.print(h);
client.print("%");
client.println("</h4>");
client.println("</center>");
client.println("</html>");
break;
}
if (c == 'n') {
currentLineIsBlank = true;
}
else if (c != 'r') {
currentLineIsBlank = false;
}
}
}
//브라우저 데이터 받는 시간
delay(1);
//연결 종료:
client.stop();
Serial.println("client disonnected");
}
}